$(document).ready(function() {
	var hRoleId = $("#hidden_role_id").val();
	getRole(hRoleId);
});

function getRole(roleId) {
	$.post(
	    "roleAction!getRole.action",
	    {"comingParams" : roleId},
	    function(data) {
	    	data = eval("("+data+")");
	    	if (data.isExit == "yes") {
	    		$("#xs_role_name").text(data.role.roleName);
		    	var statucStr = '失效';
		    	if (data.role.statusCd == '1000') {
		    		var statucStr = '生效';
		    	}
		    	$("#xs_role_status").text(statucStr);
		    	/*$("#role_privilege_detail").html("");
		    	for (var i = 0; i < data.privilegeList.length; i ++) {
		    		var spanStr = "";
		    		spanStr += "<span class='rpd-detail'>"+data.privilegeList[i].privilegeName+"</span>";
		    		$("#role_privilege_detail").append(spanStr);
		    	}*/
		  
	    	} else if (data.isExit == "no") {
	    		$.sucmodal("提交失败", "请于管理员联系",2000);
	    	}
	    	
	    }
	);
	initPrivilegeTree();
}

var treeNodes; 
function initPrivilegeTree() {
	var roleId = $("#hidden_role_id").val();
	$.ajax({  
        async : false,  
        cache:false,  
        type: 'POST', 
        data: {comingParams:roleId},
        dataType : "json",  
        url: "privilegeAction!getPrivilegeTree.action",//请求的action路径  
        error: function () {//请求失败处理函数  
            alert('请求失败');  
        },  
        success:function(data){ //请求成功后处理函数。    
        	data = eval("(" + data + ")");
            treeNodes = data.data;   //把后台封装好的简单Json格式赋给treeNodes  
        }  
    });
	var zTreeDemo = $.fn.zTree.init($("#cityTree"),setting, treeNodes);
	var nodes = zTreeDemo.getNodes();
	disabled = true, inheritParent = true, inheritChildren = true;
	for (var i = 0, l = nodes.length; i < l; i++) {
		zTreeDemo.setChkDisabled(nodes[i], disabled, inheritParent, inheritChildren);
	}
}

var setting = {
	check: {
		enable: true,
		chkStyle: "checkbox",
		chkboxType: {"Y":"ps","N":"ps"}
	},
	data: {
		simpleData: {
			enable: true
		}
	},
	edit:{
		enable:false
	}
};